const dict = new Map([['2', ['a', 'b', 'c']], ['3', ['d', 'e', 'f']], ['4', ['g', 'h', 'i']], ['5', ['j', 'k', 'l']], ['6', ['m', 'n', 'o']], ['7', ['p', 'q', 'r', 's']], ['8', ['t', 'u', 'v']], ['9', ['w', 'x', 'y', 'z']]]);

var letterCombinations = function (digits) {
    const data = digits.split('');
    const res = [];

    if (data.length) {
        let charList = dict.get(data[0]);
        for (let i = 0; i < charList.length; i++) {
            console.log('charList[i]', charList[i]);
            getDigits(data, charList[i], res, 1);
        }
    }
    console.log('res', res)
    return res
};

var getDigits = function (data, str, res, index) {
    if (index === data.length) {
        res.push(str);
        return;
    }
    console.log(dict.get(data[index]))
    let charList = dict.get(data[index]);
    for (let i = 0; i < charList.length; i++) {
        getDigits(data, str + charList[i], res, index + 1);
    }
}

letterCombinations('23');